package edu.neu.cs6515.xml;

import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * Used to make sure the unmarshalling of colors in non capital cases works fine
 */
public final class IngeniousColorAdapter extends
        XmlAdapter<String, IngeniousColor> {

    @Override
    public String marshal(final IngeniousColor arg0) throws Exception {
        return arg0.name();
    }

    @Override
    public IngeniousColor unmarshal(final String arg0) throws Exception {
        for (final IngeniousColor color : IngeniousColor.values()) {
            if (color.name().equalsIgnoreCase(arg0)) {
                return color;
            }
        }
        throw new IllegalArgumentException("Unmarshall failed");
    }
}
